﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data.SqlClient;
using System.Data;
using Common;

namespace DAL
{
    public class DQRulesConfigDAL : DB
    {
        public DQRulesConfigDAL(LoginInfo info)
        {
            base.loginInfo = info;
        }  
        public bool Insert(DQRulesConfig data, HIDB.dbo conn)
        {
            bool result = true;
            try
            {
                SqlParameter[] sqlparams = new SqlParameter[] 
                { 
                     new SqlParameter("@GUID",data.GUID)
                    ,new SqlParameter("@DQ_ID",data.DQ_ID)
                    ,new SqlParameter("@ColumnName",data.ColumnName)
                    ,new SqlParameter("@DisplayName",data.DisplayName)
                    ,new SqlParameter("@ColumnDesc",data.ColumnDesc)
                    ,new SqlParameter("@LegalOperator ",data.LegalOperator)
                    ,new SqlParameter("@LegalRules",data.LegalRules)
                    ,new SqlParameter("@ILegalOperator",data.ILegalOperator)
                    ,new SqlParameter("@IllegalRules",data.IllegalRules)
                    ,new SqlParameter("@UniqueConstraint",data.UniqueConstraint) 
                };
                conn.ExecuteSql(@"insert into [Working_db].[DQ_Rules_Config]	([GUID],DQ_ID,ColumnName,DisplayName,ColumnDesc,LegalOperator,LegalRules,ILegalOperator,IllegalRules,UniqueConstraint,CreateTime,IsDelete)
	values(@GUID,@DQ_ID,@ColumnName,@DisplayName,@ColumnDesc,@LegalOperator,@LegalRules,@ILegalOperator,@IllegalRules,@UniqueConstraint,GETDATE(),0)", sqlparams);
            }
            catch (Exception)
            {
                result = false;
                throw;
            }
            return result;
        }

        public IList<DQRulesConfig> GetListByDQID(string dqId)
        {
            IList<DQRulesConfig> result = new List<DQRulesConfig>();
            try
            {
                HIDB.dbo conn = base.conn();
                SqlParameter[] sqlparams = new SqlParameter[] { new SqlParameter("@DQ_ID", dqId) };
                DataTable dt = conn.GetDataTable("select * from [Working_db].[DQ_Rules_Config] where DQ_ID=@DQ_ID", sqlparams);
                result = DBConvert.DataTableToList<DQRulesConfig>(dt);
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
